package com.oba.demo;

import javax.faces.model.ListDataModel;

import com.oba.base.dao.DBDataModel;
import com.oba.base.service.BaseBean;

public class TestBean extends BaseBean<Test, TestService> {

	private Test test;
	private DBDataModel list = DBDataModel.create();
	private boolean showEdit = false;

	public ListDataModel getList() {
		return list;
	}

	public void doSave() {
		getService().save(test);
		doFind();
		showEdit = false;
	}

	@Override
	public String doFind() {
		list.find(getService().getDao().buileSql());
		return null;
	}
	
	public void doEditRow() {
		if(list.isRowAvailable()) {
			test = (Test) list.getRowData();
		}else {
			test = new Test();
			test.setNewBo(true);
		}
		showEdit = true;
	}
	
	public void doDeleteRow() {
		if(list.isRowAvailable()) {
			getService().del((Test)list.getRowData());
			doFind();
		}
	}

	public boolean isShowEdit() {
		return showEdit;
	}
	
	public void closeEdit() {
		showEdit = false;
	}

	public Test getTest() {
		return test;
	}

	@Override
	public void init() {
		list.find(getService().getDao().buileSql());
		System.out.println(list.getAllData().size());
	}

}
